﻿<!DOCTYPE html>
<html>
<head>
<!--
  Copyright (c) 2017-2018 Jean-Marc VIGLINO,
  released under CeCILL-B (french BSD like) licence: http://www.cecill.info/
-->
  <title>ol-ext: Search BAN control</title>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

  <meta name="description" content="Control to add a grid reference to a map." />
  <meta name="keywords" content="ol3, control, search, BAN, french, places, autocomplete" />

  <!-- FontAwesome -->
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">

  <!-- jQuery -->
  <script type="text/javascript" src="https://code.jquery.com/jquery-1.11.0.min.js"></script>
  <!-- IE 9 bug on ajax tranport  -->
  <!--[if lte IE 9]>
  <script type='text/javascript' src='//cdnjs.cloudflare.com/ajax/libs/jquery-ajaxtransport-xdomainrequest/1.0.3/jquery.xdomainrequest.min.js'></script>
  <![endif]-->

  <!-- Openlayers -->
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/ol@latest/ol.css" />
  <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/ol@latest/dist/ol.js"></script>
  <script src="https://cdn.polyfill.io/v2/polyfill.min.js?features=requestAnimationFrame,Element.prototype.classList,URL,Object.assign"></script>
  
  <!-- ol-ext -->
  <link rel="stylesheet" href="../../dist/ol-ext.css" />
  <script type="text/javascript" src="../../dist/ol-ext.js"></script>
  <!-- Pointer events polyfill for old browsers, see https://caniuse.com/#feat=pointer -->
  <script src="https://unpkg.com/elm-pep"></script>
  
  <link rel="stylesheet" href="../style.css"/>
  <style>
    .ol-search ul {
      color: #333;
      font-size:0.85em;
      max-width: 21em;
    }
    .ol-search ul i {
      display: block;
      color: #333;
      font-size:0.85em;
    }
    .info a img {
      display: inline-block;
      height: 100px;
      margin: .5em;
    }
  </style>
</head>
<body >
  <a href="https://github.com/Viglino/ol-ext" class="icss-github-corner"><i></i></a>

  <a href="../../index.html">
    <h1>ol-ext: Search BAN control</h1>
  </a>

  <div class="info">
    <i>ol.control.SearchBAN</i> is a control to search place using the 
    <a href="https://adresse.data.gouv.fr/">French National Address Base (BAN) API</a>.
    <div style="text-align: center">
      <b>In partnership with:</b><br/>
      <a href="https://portail.dgfip.finances.gouv.fr/portail/accueilIAM.pl"><img src="https://upload.wikimedia.org/wikipedia/fr/thumb/6/6d/Logo_DGFP-fr.svg/330px-Logo_DGFP-fr.svg.png" alt="DGFIP"></a>
      <a href="http://ign.fr"><img src="https://upload.wikimedia.org/wikipedia/commons/a/a0/IGN_logo_2012.svg" alt="IGN" class="jsx-3503728609 logo"></a>
      <a href="http://openstreetmap.fr"><img src="https://upload.wikimedia.org/wikipedia/commons/thumb/b/b0/Openstreetmap_logo.svg/langfr-150px-Openstreetmap_logo.svg.png" alt="OpenStreetMap France"></a>
      <a href="http://www.laposte.fr"><img src="https://upload.wikimedia.org/wikipedia/fr/thumb/0/0d/La_Poste_logo.svg/langfr-420px-La_Poste_logo.svg.png" alt="La Poste"></a>
    </div>	
    <ul>
    </ul>
    <br/>
    <i>ol.control.SearchBAN</i> use the <a href="map.control.search.html">ol.control.Search</a> control.
  </div>

  <!-- DIV pour la carte -->
  <div id="map" style="width:600px; height:400px;"></div>

  <div class="options">
    <i>Use the search control to start a new search.</i>
  </div>
  
<script type="text/javascript">
  // Layers
  var layers = [ 
    new ol.layer.Tile({ title: 'OSM', source: new ol.source.OSM(), visible: false }),
    new ol.layer.Geoportail({
      layer: 'GEOGRAPHICALGRIDSYSTEMS.PLANIGNV2', 
    }), new ol.layer.Geoportail({
      layer: 'CADASTRALPARCELS.PARCELLAIRE_EXPRESS',
      visible: false
    })
  ];

  // The map
  var map = new ol.Map ({
    target: 'map',
    view: new ol.View ({
      zoom: 5,
      center: [166326, 5992663]
    }),
    layers: layers
  });
  map.addControl(new ol.control.LayerSwitcher());

  // Set the control grid reference
  var search = new ol.control.SearchBAN({
    //target: $(".options").get(0),
    reverse:true,
    position: true	// Search, with priority to geo position
  });
  map.addControl (search);

  // Select feature when click on the reference index
  search.on('select', function(e) {
    // console.log(e);
    map.getView().animate({
      center:e.coordinate,
      zoom: Math.max (map.getView().getZoom(),16)
    });
  });

</script>
  
</body>
</html>